<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Easy Url Task</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/bootstrap.min.css">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/font-awesome.min.css">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="${request.contextPath}/statics/css/all-skins.min.css">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/main.css">
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body class="hold-transition login-page">
<div class="login-box" id="rrapp" v-cloak>
  <div class="login-logo">
    <b>Easy Url Task</b>
  </div>
  <!-- /.login-logo -->
    <div class="login-box-body" v-show="agree===false">
        <p class="login-box-msg" style="font-weight: bold">by zhengkai.blog.csdn.net<br>
            Open Source Project</p>
      <p>人生得意须尽欢，莫使金樽空对月。</p>
      <p>天生我材必有用，千金散尽还复来。</p>
        <button type="button" class="btn btn-primary btn-block btn-flat" @click="agreeIt">确认</button>
    </div>
    <div class="login-box-body" v-show="agree===true">
      <p class="login-box-msg">企业登录</p>
      <div v-if="error" class="alert alert-danger alert-dismissible">
        <h4 style="margin-bottom: 0px;"><i class="fa fa-exclamation-triangle"></i> {{errorMsg}}</h4>
      </div>
      <div class="form-group has-feedback">
        <input type="text" class="form-control" v-model="token" placeholder="TOKEN">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="text" class="form-control" v-model="captcha" @keyup.enter="login" placeholder="验证码">
        <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
      </div>

      <div class="row">
        <!--<div class="col-xs-8">
            <button type="button" class="btn btn-block btn-flat" @click="register">还没企业账号，注册一个？</button>
        </div>-->
        <!-- /.col -->
        <div class="col-xs-4">
            <button type="button" class="btn btn-primary btn-block btn-flat" @click="login">登录</button>
        </div>
        <!-- /.col -->
      </div>
    <!-- /.social-auth-links -->

  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->
<script src="${request.contextPath}/statics/libs/jquery.min.js"></script>
<script src="${request.contextPath}/statics/libs/vue.min.js"></script>
<script src="${request.contextPath}/statics/libs/bootstrap.min.js"></script>
<script src="${request.contextPath}/statics/libs/jquery.slimscroll.min.js"></script>
<script src="${request.contextPath}/statics/libs/fastclick.min.js"></script>
<script src="${request.contextPath}/statics/libs/app.js"></script>
<script type="text/javascript">
var vm = new Vue({
	el:'#rrapp',
	data:{
		token: '',
		captcha: '1234',
		error: false,
		errorMsg: '',
		src: 'captcha.jpg',
        agree:true
	},
	beforeCreate: function(){
		if(self != top){
			top.location.href = self.location.href;
		}
	},
	methods: {
		refreshCode: function(){
			this.src = "captcha.jpg?t=" + $.now();
		},
        agreeIt : function(){
            this.agree=true;
        },
		login: function (event) {
          const data = "token=" + vm.token.trim() + "&captcha=" + vm.captcha;
          if(vm.token.length<10||vm.captcha.length<4){
                vm.error = true;
                vm.errorMsg = "请输入超过十位的合法TOKEN和大于四位的验证码";
                return;
            }
			$.ajax({
				type: "POST",
			    url: "login",
			    data: data,
			    dataType: "json",
			    success: function(r){
					if(r.code === 0){//登录成功
						parent.location.href ='index';
					}else{
						vm.error = true;
						vm.errorMsg = r.msg;
					}
				}
			});
		}/*,
        register: function (event) {
          const data = "username=" + vm.username + "&password=" + vm.password + "&captcha=" + vm.captcha;
          location.href ='register.html';
        }*/
	}
});
</script>
</body>
</html>
